<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<html:html>
<head>	
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/sampleForm.css" />
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/me.css" />	
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/common/css/help/help.css" />
	<title>บันทึกใบซื้ออุปกรณ์, วัตถุดิบ (BCAPInvoice, BCAPInvoiceSub)</title>
	<script type='text/javascript' src='/ittl/dwr/interface/BCProjectService.js'></script>
  	<script type='text/javascript' src='/ittl/dwr/interface/ItemLocationService.js'></script>
  	<script type='text/javascript' src='/ittl/dwr/interface/BCAPInvoiceService.js'></script>
  	<script type='text/javascript' src='/ittl/dwr/engine.js'></script>
  	<script type='text/javascript' src='/ittl/dwr/util.js'></script>

	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/jquery.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/jquery.bgiframe.min.js1' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/jquery.ajaxQueue.js1' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/thickbox-compressed.js1' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/jquery.autocomplete.js' ></script>
	
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdata.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdata2.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/codeOfBuyRequest.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdata31.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdataDepartment.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/localdataDepartmentName.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/apCodeName.js' ></script>
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/data/apCode.js' ></script>
	
	
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/autocomplete/css/mainOLD.css" />
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/autocomplete/css/jquery.autocomplete.css" />
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/autocomplete/css/thickbox.css" />
 
 	<script type="text/javascript" src="<%= request.getContextPath() %>/stockRequest/jquery.validate.js" ></script>
 	<script type="text/javascript" src="<%= request.getContextPath() %>/stockRequest/jquery-1.4.2.min1.js" ></script>

<!-- start 
 
	<link type="text/css" href="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/themes/base/jquery.ui.all.css" rel="stylesheet" />
	<link type="text/css" href="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/demos/demos.css" rel="stylesheet" />
	  	
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/jquery-1.4.2.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/external/jquery.bgiframe-2.1.1.js"></script>			
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.core.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.widget.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.mouse.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.button.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.draggable.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.position.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.resizable.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.dialog.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.effects.core.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.datepicker.js"></script>
	<script type="text/javascript" src="<%= request.getContextPath() %>/jquery-ui-1.8/development-bundle/ui/jquery.ui.autocomplete.js"></script>
			
-->
<!-- end -->

<!-- start add/remove  
	<script type="text/javascript" src='<%= request.getContextPath() %>/common/js/addremove/jquery-latest.pack.js'></script>	
-->	
	<script type="text/javascript" src='<%= request.getContextPath() %>/common/js/addremove/jquery.highlightFade.js'></script>
	<script type="text/javascript">
		
	var id = 1;	

	var idArray = new Array();
	for(i=0;i<=15;i++) {
		idArray[i] = 0;	
	}

	var max = false;
	
	function addFormField() {
		max = true;
		for (i=1; i<idArray.length; i++) {
			if(idArray[i]==0) {
				
				
				
				max = false;
				idArray[i] = 1;
				id = i+1; 
				i = idArray.length;
								
				var newInput = "<tr id='r"+id+"'>"+
									"<td><a href='#' onClick='removeFormField(\"#r" + id + "\","+id+"); return false;'>"+
										"<img src=\"<%=request.getContextPath() %>/common/images/remove.png\" width=\"24\" height=\"24\" alt=\"Remove\" /></a></td>"+
									"<td><input	type='text' name='itemCode"+id+"' value='' size='12' "+
												" onblur=\"getData(document.getElementById('itemCode"+id+"').value,"+id+")\" id=\"itemCode"+id+"\"> "+ 											     
										"</td><td></td> "+
										"<td><input type='text' name='itemName"+id+"' value='' maxlength='200' size='40' id='itemName"+id+"' >"+														
									"</td><td></td>"+

									
									"<td align='center'><input type='text' name='unitName"+id+"' value='' size='5' id='unitName"+id+"' >"+																																
									"	 <input	type='hidden' name='unitCode"+id+"' value='' id='unitCode"+id+"'>"+
									"</td><td></td>"+									
									"<td><input	type='text'	name='qty"+id+"' value=''  size='5' id='qty"+id+"' onblur='calLineItem("+id+");' ></td><td></td>"+
									"<td><input	type='text'	name='price"+id+"' value='' size='5' id='price"+id+"' onblur='calLineItem("+id+");' ></td>"+
									"<td></td>"+
									"<td><input	type='text'	name='amount"+id+"' value='' size='5' id='amount"+id+" ></td>"+
									"<td></td>"+									
									"<td><input	type='text'	name='division"+id+"' value='' id='division"+id+"' ></td>"+
									"<td></td>"+
								"</tr>";
																						  
																					
//							<td>${fullForm.stkReqNo1 }<input	type="hidden" name="stkReqNo1" value="${fullForm.stkReqNo1}" id="stkReqNo1"></td>
//							<td><input	type="hidden" name="confirmNo1" value="${fullForm.confirmNo1}" id="confirmNo1"></td>

								
				
				
				$("#inputs").append(newInput); 
				$('#r' + id).highlightFade({
					speed:2000
				});			
				$("#itemCode1a"+id).autocomplete(codes, {
					max:30,
					minChars: 0,
					autoFill: true,
					mustMatch: true,
					matchContains: false,
					scrollHeight: 200				
				});

				$("#itemCode"+id).autocomplete(itemsName, {
					minChars: 0,
					width: 400,
					max:50,
					mustMatch: true,
					matchContains: true,
					autoFill: false,
					formatItem: function(row, i, max) {
						return row.code + ": [" + row.name + "]";
					},
					formatMatch: function(row, i, max) {
						return row.code + ": [" + row.name + "]";
					},
					formatResult: function(row) {
						return row.code;
					}
				});								
			}
		}
						
		if(max==true) {											 	
			alert("คุณสามารถเพิ่มข้อมูลได้สูงสุด 15 รายการ");
		}				
	}
	
	function removeFormField(rid, id) {
		var count = 0;
		for (i=0; i<idArray.length; i++) {
			if(idArray[i]>0) {
				count++;
			}
		}		
		if(count>1) {
			$(rid).remove();
			idArray[id-1] = 0;
		}else {
			alert("กรุณาบันทึกข้อมูลอย่างน้อย 1 รายการ");
		}
		
	}
		
	</script>
<!-- end add/remove  -->

<style type="text/css">
#form1 label.error {
	font-size: 1.0em;
	color: red;
}
</style>
 	
<script language="JavaScript">
 
function compareBuga() {
	return "buga22";
}

$.validator.addMethod("buga", function(value) {
	return value == compareBuga();
}, 'Please enter "buga"!');

$(document).ready(function() {
	 
	
	$("#form1").validate({
		
			
		submitHandler: function() {
			alert("txt1="+document.getElementById("txt1").value);
			alert("submitted!22");
			//$('#dialog-confirm').dialog('open');
			form.submit();
		},
				
		rules: {
			txt1: "required",
			docNo: "required",
			docDate: "required",
			apCode: "required",
			iTTL_deptPay: "required",
			projectCode: "required",

			itemCode1: "required",
			itemCode2: "required",				
			itemCode3: "required",
			itemCode4: "required",
			itemCode5: "required",
			itemCode6: "required",
			itemCode7: "required",				
			itemCode8: "required",
			itemCode9: "required",
			itemCode10: "required",
			itemCode11: "required",
			itemCode12: "required",				
			itemCode13: "required",
			itemCode14: "required",
			itemCode15: "required",
			
			itemName1: "required",
			itemName2: "required",
			itemName3: "required",
			itemName4: "required",
			itemName5: "required",
			itemName6: "required",
			itemName7: "required",
			itemName8: "required",
			itemName9: "required",
			itemName10: "required",
			itemName11: "required",
			itemName12: "required",
			itemName13: "required",
			itemName14: "required",
			itemName15: "required",								
			
			unitName1: "required",
			unitName2: "required",
			unitName3: "required",
			unitName4: "required",
			unitName5: "required",
			unitName6: "required",
			unitName7: "required",
			unitName8: "required",
			unitName9: "required",
			unitName10: "required",
			unitName11: "required",
			unitName12: "required",
			unitName13: "required",
			unitName14: "required",
			unitName15: "required",
				
			poRefNo1: "required",
			poRefNo2: "required",
			poRefNo3: "required",
			poRefNo4: "required",
			poRefNo5: "required",
			poRefNo6: "required",
			poRefNo7: "required",
			poRefNo8: "required",
			poRefNo9: "required",
			poRefNo10: "required",
			poRefNo11: "required",
			poRefNo12: "required",
			poRefNo13: "required",
			poRefNo14: "required",
			poRefNo15: "required",
					
			qty1: {required: 	true,	number:		true},
			qty2: {required: 	true,	number:		true},
			qty3: {required: 	true,	number:		true},
			qty4: {required: 	true,	number:		true},
			qty5: {required: 	true,	number:		true},
			qty6: {required: 	true,	number:		true},
			qty7: {required: 	true,	number:		true},
			qty8: {required: 	true,	number:		true},
			qty9: {required: 	true,	number:		true},
			qty10: {required: 	true,	number:		true},
			qty11: {required: 	true,	number:		true},
			qty12: {required: 	true,	number:		true},
			qty13: {required: 	true,	number:		true},
			qty14: {required: 	true,	number:		true},
			qty15: {required: 	true,	number:		true},

			price1: {required: 	true,	number:		true},
			price2: {required: 	true,	number:		true},
			price3: {required: 	true,	number:		true},
			price4: {required: 	true,	number:		true},
			price5: {required: 	true,	number:		true},
			price6: {required: 	true,	number:		true},
			price7: {required: 	true,	number:		true},
			price8: {required: 	true,	number:		true},
			price9: {required: 	true,	number:		true},
			price10: {required: 	true,	number:		true},
			price11: {required: 	true,	number:		true},
			price12: {required: 	true,	number:		true},
			price13: {required: 	true,	number:		true},
			price14: {required: 	true,	number:		true},
			price15: {required: 	true,	number:		true},

			discountAmount1: {required: 	true,	number:		true},
			discountAmount2: {required: 	true,	number:		true},
			discountAmount3: {required: 	true,	number:		true},
			discountAmount4: {required: 	true,	number:		true},
			discountAmount5: {required: 	true,	number:		true},
			discountAmount6: {required: 	true,	number:		true},
			discountAmount7: {required: 	true,	number:		true},
			discountAmount8: {required: 	true,	number:		true},
			discountAmount9: {required: 	true,	number:		true},
			discountAmount10: {required: 	true,	number:		true},
			discountAmount11: {required: 	true,	number:		true},
			discountAmount12: {required: 	true,	number:		true},
			discountAmount13: {required: 	true,	number:		true},
			discountAmount14: {required: 	true,	number:		true},
			discountAmount15: {required: 	true,	number:		true},

			amount1: {required: 	true,	number:		true},
			amount2: {required: 	true,	number:		true},
			amount3: {required: 	true,	number:		true},
			amount4: {required: 	true,	number:		true},
			amount5: {required: 	true,	number:		true},
			amount6: {required: 	true,	number:		true},
			amount7: {required: 	true,	number:		true},
			amount8: {required: 	true,	number:		true},
			amount9: {required: 	true,	number:		true},
			amount10: {required: 	true,	number:		true},
			amount11: {required: 	true,	number:		true},
			amount12: {required: 	true,	number:		true},
			amount13: {required: 	true,	number:		true},
			amount14: {required: 	true,	number:		true},
			amount15: {required: 	true,	number:		true}
			
		},
		messages: {
			txt1: "*",
			docNo: "*",
			docDate: "*",
			apCode: "*",
			iTTL_deptPay: "*",
			projectCode: "*",

			itemCode1: "*",
			itemCode2: "*",				
			itemCode3: "*",
			itemCode4: "*",
			itemCode5: "*",
			itemCode6: "*",
			itemCode7: "*",				
			itemCode8: "*",
			itemCode9: "*",
			itemCode10: "*",
			itemCode11: "*",
			itemCode12: "*",				
			itemCode13: "*",
			itemCode14: "*",
			itemCode15: "*",
			
			itemName1: "*",
			itemName2: "*",
			itemName3: "*",
			itemName4: "*",
			itemName5: "*",
			itemName6: "*",
			itemName7: "*",
			itemName8: "*",
			itemName9: "*",
			itemName10: "*",
			itemName11: "*",
			itemName12: "*",
			itemName13: "*",
			itemName14: "*",
			itemName15: "*",								
			
			unitName1: "*",
			unitName2: "*",
			unitName3: "*",
			unitName4: "*",
			unitName5: "*",
			unitName6: "*",
			unitName7: "*",
			unitName8: "*",
			unitName9: "*",
			unitName10: "*",
			unitName11: "*",
			unitName12: "*",
			unitName13: "*",
			unitName14: "*",
			unitName15: "*",
				
			qty1: "*",
			qty2: "*",
			qty3: "*",
			qty4: "*",
			qty5: "*",
			qty6: "*",
			qty7: "*",
			qty8: "*",
			qty9: "*",
			qty10: "*",
			qty11: "*",
			qty12: "*",
			qty13: "*",
			qty14: "*",
			qty15: "*",

			price1: "*",
			price2: "*",
			price3: "*",
			price4: "*",
			price5: "*",
			price6: "*",
			price7: "*",
			price8: "*",
			price9: "*",
			price10: "*",
			price11: "*",
			price12: "*",
			price13: "*",
			price14: "*",
			price15: "*",

			discountAmount1: "*",
			discountAmount2: "*",
			discountAmount3: "*",
			discountAmount4: "*",
			discountAmount5: "*",
			discountAmount6: "*",
			discountAmount7: "*",
			discountAmount8: "*",
			discountAmount9: "*",
			discountAmount10: "*",
			discountAmount11: "*",
			discountAmount12: "*",
			discountAmount13: "*",
			discountAmount14: "*",
			discountAmount15: "*",

			amount1: "*",
			amount2: "*",
			amount3: "*",
			amount4: "*",
			amount5: "*",
			amount6: "*",
			amount7: "*",
			amount8: "*",
			amount9: "*",
			amount10: "*",
			amount11: "*",
			amount12: "*",
			amount13: "*",
			amount14: "*",
			amount15: "*",

			poRefNo1: "*",
			poRefNo2: "*",
			poRefNo3: "*",
			poRefNo4: "*",
			poRefNo5: "*",
			poRefNo6: "*",
			poRefNo7: "*",
			poRefNo8: "*",
			poRefNo9: "*",
			poRefNo10: "*",
			poRefNo11: "*",
			poRefNo12: "*",
			poRefNo13: "*",
			poRefNo14: "*",
			poRefNo15: "*"
	
		},

		// the errorPlacement has to take the table layout into account
		errorPlacement: function(error, element) {
			//alert("errorPlacement");			
			if ( element.is(":radio") ) {
				alert("radio");
				error.appendTo( element.parent().next().next() );
			}else if ( element.is(":checkbox") ) {
				alert("checkbox");
				error.appendTo ( element.next() );
			}else {
				/*alert(element("#itemCode1"));
				if(element.is("#itemCode1")) {
					error.appendTo( "#qty1-error" );
				}else {
					error.appendTo( element.parent().next() );	
				}*/
				//error.insertAfter('#qty1-error');
				error.appendTo( element.parent().next() );
			}
		}		
	});
	

	$("#suggest1").focus().autocomplete(cities);
	
	$("#suggestProject").autocomplete(projects, {		
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});

	
	$("#departCode").autocomplete(departments, {		
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});
			
	$("#suggestDeptPay").autocomplete(departments, {		
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});
			
	$("#suggestCode1").autocomplete(codes, {
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200				
	});
	
	$("#suggestCode2").autocomplete(codes, {
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});
	
	$("#suggestCode3").autocomplete(codes, {
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});
	
	$("#suggestCode4").autocomplete(codes, {
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});
	$("#suggestCode5").autocomplete(codes, {
		max:30,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});


	
	
	$("#suggest11").autocomplete(cities, {
		matchContains: true,
		minChars: 0
	});

    $("#itemName5").autocomplete(cities, { scroll: true } );

	$("#suggest4").autocomplete(emails, {
		minChars: 0,
		
		matchContains: true,
		autoFill: false,
		formatItem: function(row, i, max) {
			return i + "/" + max + ": \"" + row.name + "\" [" + row.to + "]";
		},
		formatMatch: function(row, i, max) {
			return row.name + " " + row.to;
		},
		formatResult: function(row) {
			return row.to;
		}
	});

	$("#division1OLD").autocomplete(departmentsName, {
		minChars: 0,
		mustMatch: true,
		matchContains: true,
		autoFill: false,
		formatItem: function(row, i, max) {
			return row.code + ": [" + row.name + "]";
		},
		formatMatch: function(row, i, max) {
			return row.code + ": [" + row.name + "]";
		},
		formatResult: function(row) {
			return row.name;
		}
	});	

	for(i=1;i<=15;i++) {
		$("#itemCode"+i).autocomplete(itemsName, {
			minChars: 0,
			width: 400,
			max:50,
			mustMatch: true,
			matchContains: true,
			autoFill: false,
			formatItem: function(row, i, max) {
				return row.code + ": [" + row.name + "]";
			},
			formatMatch: function(row, i, max) {
				return row.code + ": [" + row.name + "]";
			},
			formatResult: function(row) {
				return row.code;
			}
		});
	}

	$("#suggestAp").autocomplete(apCode, { scroll: true } );
	
	$("#apCode").autocomplete(apCode, {		
		max:50,
		minChars: 0,
		autoFill: true,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 200
	});
	
	$("#itemCode5").autocomplete(itemsName, {
		minChars: 0,
		width: 400,
		max:50,
		mustMatch: true,
		matchContains: true,
		autoFill: false,
		formatItem: function(row, i, max) {
			return row.code + ": [" + row.name + "]";
		},
		formatMatch: function(row, i, max) {
			return row.code + ": [" + row.name + "]";
		},
		formatResult: function(row) {
			return row.code;
		}
	});	
			
});

</script>  

<!--  ส่วนที่ 2 -->
<script language="JavaScript">
var inputNo;
var itemName = "";
var code;
var itemName;
var whCode;
var shelfCode;
var shelfName;

function getData(var1,x) {	
	inputNo = x;
	ItemLocationService.getData( var1, loadinfo );	  
}

//<!--  ส่วนที่ 3 -->
function loadinfo(data)
{
	code 	  = data.code;
	itemName  = data.name1;
	whCode 	  = data.whCode;
	shelfCode = data.shelfCode;
	shelfName = data.shelfName;
	unitCode = data.unitCode;
	unitName = data.unitName;

	ittl_row = data.ittl_row;
	ittl_shelf = data.ittl_shelf;
	
	
		dwr.util.setValue("itemCode"+inputNo, code);
			dwr.util.setValue("itemName"+inputNo, itemName);
			dwr.util.setValue("whCode"+inputNo, whCode);			
			dwr.util.setValue("unitCode"+inputNo, unitCode);
			dwr.util.setValue("unitName"+inputNo, unitName);
			//redirectN(0, document.getElementById('shCode1'));
			//redirectN(0, document.getElementById('shCode5'));//ใช้ document.form1.shelfCode5 จะทำงานได้บน IE แต่ไม่ไได้บน FF
			dwr.util.setValue("ittl_row"+inputNo, ittl_row);
			dwr.util.setValue("ittl_shelf"+inputNo, ittl_shelf);
								
			
}

function redirectN(x, tempN){
	
	var groupsN=5;//document.form1.shelfCode1.options.length
	var groupN=new Array(groupsN);
	for (i=0; i<groupsN; i++)
		groupN[i]=new Array();

	//var tempN=document.form1.shelfCode1;	
	//alert("tempN.options.length-1 = "+(tempN.options.length-1));
	for (m=tempN.options.length-1;m>=0;m--) {
		//alert(tempN.options[m]);
		tempN.options[m]=null;
	}
	
	if(shelfName != null) {
		for (i=0; i<shelfName.length; i++) {
			groupN[0][i]=new Option(shelfName[i], shelfCode[i]);
		}
					
		for (i=0;i<groupN[x].length;i++){
			text = groupN[x][i].value+":"+groupN[x][i].text;
			tempN.options[i]=new Option(text,groupN[x][i].value);
		}
		tempN.options[0].selected=true;
	}
}
</script>
<!--  ส่วนที่ 2 -->
<script language="JavaScript">

function getProject() {
	//alert("bcproject"+form1.projectCode.value); ใช้ใน ff ไม่ผ่าน			
	BCProjectService.getProject( document.getElementById("suggestProject").value, loadinfoProject );			  
}

//<!--  ส่วนที่ 3 -->
function loadinfoProject(project){		
	//dwr.util.setValue("projectCode", project.name);
	dwr.util.setValue("projectName", project.name);			     
}
</script>

<!--  ส่วนที่ 2 -->
<script language="JavaScript">

function getMaxDocNo() {
	
	var sel = document.getElementById("preDocNo");
		
	//alert(sel.options[sel.selectedIndex].value);
	
	BCAPInvoiceService.getMaxDocNo(sel.options[sel.selectedIndex].value, loadinfoDocNo);			  
}

//<!--  ส่วนที่ 3 -->
function loadinfoDocNo(maxDocNo){		
	
	dwr.util.setValue("docNo", maxDocNo.docNo);

//	alert("aa");
	var mySelect = document.getElementById("preDocNo");
	
	for(var i=0; i<mySelect.options.length; i++) {
		if(mySelect.options[i].selected==true && mySelect.options[i].value=="BCS-") {
			document.getElementById("refNo").options[1].selected=true;		
			break;
		}else {
			document.getElementById("refNo").options[0].selected=true;
		}
	}
				     
}
</script>	

<script type="text/javascript">
function alertValue() {
	alert(document.getElementById('htmlElementTest').value)
}
</script>

	<link type="text/css" href="<%= request.getContextPath() %>/css/datepicker/css/ui.all.css" rel="stylesheet" /> 
	
	<script type="text/javascript" src="<%= request.getContextPath() %>/css/datepicker/lib/jquery-ui-1.5.3.min.js"></script>
	

	<script type="text/javascript">
		$(document).ready(function(){
    			$("#docDate").datepicker({ altField: 'input#docDate', altFormat: 'yy-mm-dd' });
    			$("#taxDate").datepicker({ altField: 'input#taxDate', altFormat: 'yy-mm-dd' });
  		});
	</script>

<script type="text/javascript">
	var sumOfLineItemAmount = new Array();
	var sumOfAmount = 0;
	var qty = 0;
	var price = 0;
	var disAmt =0;
	var discountAmount = 0;
	var taxAmount = 0;
	
	var qtyArray = new Array();
	for(var i=1; i<=15; i++) {
		qtyArray[i]=0;
		sumOfLineItemAmount[i] = 0;
	}
	
function calUnitPrice(id) {
	
	qty = document.getElementById('qty'+id).value;	
	disAmt = document.getElementById('discountAmount'+id).value
	if(disAmt=="") {
		disAmt = 0;
	}	
//	alert("before sumOfAmount = "+sumOfAmount);
	sumOfAmount -= sumOfLineItemAmount[id];
//	alert("after sumOfAmount = "+sumOfAmount);
	sumOfLineItemAmount[id] = document.getElementById('amount'+id).value;
	sumOfAmount = sumOfAmount*1+sumOfLineItemAmount[id]*1;

//	alert("after sumOfAmount disAmt= "+sumOfAmount);
	document.getElementById('discountAmount'+id).value =0;
	document.getElementById('price'+id).value = sumOfLineItemAmount[id]/qty;

	var discountAmount = document.getElementById('discountAmount').value;
	alert("sumOfAmount="+sumOfAmount);
	document.getElementById('sumOfItemAmount').value = sumOfAmount;
	document.getElementById('totalAmount').value = parseFloat(sumOfAmount-discountAmount).toFixed(2);
	document.getElementById('netAmount').value = parseFloat(sumOfAmount-discountAmount).toFixed(2);
	document.getElementById('discountAmount'+id).value=disAmt;			 
}

function calLineItem(id) {

	//sumOfAmount = calSumAmount() - sumOfLineItemAmount[id];

	//alert("1.sumOfAmount="+sumOfAmount);
	//alert("calSumAmount()="+calSumAmount());
	//
	
	qty = document.getElementById('qty'+id).value;
	price = document.getElementById('price'+id).value;
	disAmt = document.getElementById('discountAmount'+id).value;
	if(disAmt=="") {
		disAmt = 0;
	}
	sumOfLineItemAmount[id] = parseFloat(qty*price-disAmt).toFixed(2);
	alert("sumOfLineItemAmount[id] = "+sumOfLineItemAmount[id]);
	document.getElementById('amount'+id).value = parseFloat(sumOfLineItemAmount[id]).toFixed(2);

	
	
	sumOfAmount = calSumAmount();//sumOfAmount*1+sumOfLineItemAmount[id]*1;
	
	
	document.getElementById('discountAmount').value = parseFloat("0").toFixed(2);	
	document.getElementById('sumOfItemAmount').value = parseFloat(sumOfAmount).toFixed(2);
	
	var vat = 0;
	if(document.getElementById('taxNo').value!="") {
		vat = calTaxAmount();
		document.getElementById('taxAmount').value = parseFloat(vat).toFixed(2);
	}else {
		document.getElementById('taxAmount').value = parseFloat("0").toFixed(2);;
	}

	document.getElementById('totalAmount').value = parseFloat(sumOfAmount*1+vat*1).toFixed(2);
	document.getElementById('netAmount').value = parseFloat(sumOfAmount*1+vat*1).toFixed(2);
	document.getElementById('payAmount').value = parseFloat(sumOfAmount*1+vat*1).toFixed(2);
	document.getElementById('price'+id).value = parseFloat(price).toFixed(2);
	document.getElementById('discountAmount'+id).value=parseFloat(disAmt).toFixed(2);	
}

function calTaxAmount() {
	sumOfItemAmount = 0;
	discountAmount = 0;
	if(document.getElementById('taxNo').value!="") {
		sumOfItemAmount = parseFloat(document.getElementById('sumOfItemAmount').value);

		if(document.getElementById('discountAmount').value!="") {
			discountAmount = parseFloat(document.getElementById('discountAmount').value);										
		}	
		var taxAmount = parseFloat((sumOfItemAmount-discountAmount)*0.07).toFixed(2);
		
		document.getElementById('taxAmount').value  = parseFloat(taxAmount).toFixed(2);
		document.getElementById('totalAmount').value= parseFloat(sumOfItemAmount*1+taxAmount*1-discountAmount).toFixed(2);
		document.getElementById('netAmount').value 	= parseFloat(sumOfItemAmount*1+taxAmount*1-discountAmount).toFixed(2);
		document.getElementById('payAmount').value 	= parseFloat(sumOfItemAmount*1+taxAmount*1-discountAmount).toFixed(2);
									
	}else {
		if(document.getElementById('sumOfItemAmount').value!="") {
			sumOfItemAmount = parseFloat(document.getElementById('sumOfItemAmount').value);
		}
		if(document.getElementById('discountAmount').value!="") {
			discountAmount = parseFloat(document.getElementById('discountAmount').value);										
		}		
		document.getElementById('taxAmount').value  = parseFloat("0").toFixed(2);		
		document.getElementById('totalAmount').value= parseFloat(sumOfItemAmount*1-discountAmount).toFixed(2);
		document.getElementById('netAmount').value 	= parseFloat(sumOfItemAmount*1-discountAmount).toFixed(2);
		document.getElementById('payAmount').value 	= parseFloat(sumOfItemAmount*1-discountAmount).toFixed(2);
	}
	
	document.getElementById('discountAmount').value = parseFloat(discountAmount).toFixed(2);
	document.getElementById('sumOfItemAmount').value = parseFloat(sumOfItemAmount).toFixed(2);
	
	return taxAmount;
}

function dataToPayAmount() {
	//alert("datatopay");
	var mySelect = document.getElementById("preDocNo");
	for(var i=0; i<mySelect.options.length; i++) {
		if(mySelect.options[i].selected==true && mySelect.options[i].value=="BCS-") {
			document.getElementById('payAmount').value = document.getElementById('netAmount').value;					
			break;
		}else {
			document.getElementById('payAmount').value = 0;
		}
	}	
}

function calSumAmount() {
	sumOfAmount = 0;
	for(var i=1; i<=15; i++) {		
		sumOfAmount = sumOfAmount*1+sumOfLineItemAmount[i]*1;
	}
	return sumOfAmount;
}


</script>
</head>

<body><br />
<div id="wrapper">
	 
	<div id="menu"><ul id="nav"></ul></div>

	<div id="content">
		<div id="menuNav"><a href='<%=request.getContextPath() %>/Login.do?mode=check'>หน้าหลัก</a> 
		>> คลังพัสดุ - Store กลาง  >> จัดซื้อ >> บันทึกซื้อสินค้า และบริการ </div><br />
			
	<div style="background: #ffffff;">
	<p align="center" id="titleIssueType">บันทึกใบซื้ออุปกรณ์, วัตถุดิบ </p>
	
	<html:form action="/apinvoice.do?mode=add" styleId="form1"  >	        
                <input type="hidden" name="creatorCode" value="${invForm.creatorCode }" />
                <input type="hidden" name="lastEditorCode" value="${userName }" />
                
                
	<div id="userPw01">
	<fieldset>
		<legend><b>ข้อมูลใบซื้ออุปกรณ์, วัตถุดิบ</b></legend>
		   <center> 
		   <table border="0" >
			<tr>
				<td width="160" align="right">ประเภทการซื้อ:</td>
				<td width="140"><select name="billType">
									<option value="0">ซื้อสินค้าเงินสด</option>
									<option value="1">ซื้อสินค้าเงินเชื่อ</option>
									<option value="2">ซื้อบริการเงินสด</option>
									<option value="3">ซื้อบริการเงินเชื่อ</option>
									 </select> </td>
				<td width="20"></td>				
				<td width="160" align="right">ประเภทการซื้อ:</td>
				<td width="140"><select name="taxType">
									<option value="0">ภาษีแยกนอก</option>
									<option value="1">ภาษีรวมใน</option>
									<option value="2">ภาษีอัตราศูนย์</option>									
									 </select> </td>
				<td width="20"></td>
			</tr>		   		   
			<tr>
				<td width="160"align="right"> เลขที่ใบซื้อ:</td>
				<td width="140">
								<input type="text" name="docNo" value="${invForm.docNo }" id="docNo" onblur="getMaxDocNo()"></td>
				<td width="20"></td>				
				<td width="160"align="right"> วันที่ออกเอกสาร:</td>
				<td width="160"><input type="text" name="docDate" id="docDate" value="${invForm.docDate }"></td>
				<td width="20"></td>					
			</tr>
			<tr>
				<td width="160"align="right"> เลขที่ใบกำกับภาษี:</td>
				<td width="140"><input type="text" name="taxNo" value="${invForm.taxNo }" id="taxNo" onchange="calTaxAmount()"></td>
				<td width="20"></td>				
				<td width="160"align="right"> วันที่ใบกำกับภาษี:</td>
				<td width="160"><input type="text" name="taxDate" id="taxDate" value="${invForm.taxDate }"></td>
				<td width="20"></td>					
			</tr>
			<tr>			
 				<td align="right">รหัสเจ้าหนี้:</td>
 				<td><input type="text" name="apCode" value="${invForm.apCode }" id="apCode" ></td>
 				<td ></td> 				
 				<td colspan="3">ชื่อ<input type="text" name="apName" value="" id="apName" readonly="readonly" size="40">
 										 				 			
 			</tr>													 			 				 							
		</table>
		</center>
     </fieldset></div>
    <div id="items"> 
     <fieldset>
     	<legend><b>รายการอุปกรณ์, วัตถุดิบ</b></legend>     	
<!--      	     	
     	<p><a href="#" onClick="addFormField(); return false;">
     			<img src="<%=request.getContextPath() %>/common/images/add.png" width="24" height="24" alt="Add" />
     		</a>     			   
     	</p>
 -->     	
     		<input type="hidden" id="id" value="0">
     	<center>	     		          	
		<table border="0" >
			<thead>
				<tr id="rHead">
					<th width="24"></th>
				  <th width="100" align="center">รหัสสินค้า</th>
				  <th width="10">&nbsp;</th>
				  <th width="270" align="center">ชื่อรายการ</th>
				  <th width="10">&nbsp;</th>				

				  <th width="70"  align="center">หน่วยนับ</th>
				  <th width="10">&nbsp;</th>
				  <th width="60"  align="center">จำนวน</th>
				  <th width="10">&nbsp;</th>
				  <th width="60"  align="center">ราคาซื้อ</th>
				  <th width="10">&nbsp;</th>				
				  <th width="60"  align="center">ส่วนลด</th>
				  <th width="10">&nbsp;</th>				    
				  <th width="70"  align="center">จำนวนเงิน</th>
				  <th width="10">&nbsp;</th>				  
				  <th width="80"  >เลขที่ใบPO</th>
				  <th width="10">&nbsp;</th>				
				</tr>						
			</thead>
			
			<tbody id="inputs" >
<c:if test="${!empty invForm.itemCode1}"> 			
				<tr id="r1">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode1" value="${invForm.itemCode1 }" size="12"  id="itemCode1"
				  				onchange="getItem(document.getElementById('itemCode1').value,1)"  >			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName1" value="${invForm.itemName1 }" maxlength="200" size="40" id="itemName1">					
					</td><td></td>
										
					<td align="center"><input	type="text"	name="unitName1" value="${invForm.unitName1 }" size="5" id="unitName1" >					
						<input	type="hidden" name="unitCode1" value="${invForm.unitCode1 }" id="unitCode1">
					</td><td></td>
					<td><input	type="text"	name="qty1" value="${invForm.qty1 }"  size="5" id="qty1" onchange="calLineItem(1);" ></td>
					<td></td>
					<td><input	type="text"	name="price1" value="${invForm.price1 }" size="5" id="price1" onchange="calLineItem(1);" ></td>
					<td></td>
					<td><input	type="text"	name="discountAmount1" value="${invForm.discountAmount1 }" size="5" id="discountAmount1" onchange="calLineItem(1);" ></td>
					<td></td>					
					<td><input	type="text"	name="amount1" value="${invForm.amount1 }" size="5" id="amount1" onchange="calUnitPrice(1)"></td>
					<td></td>
					<td><input	type="text"	name="poRefNo1" value="${invForm.poRefNo1 }" size="5" id="poRefNo1" >
						<input	type="hidden" name="stkReqNo1" value="" id="stkReqNo1"></td>
					<td><input	type="hidden" name="confirmNo1" value="" id="confirmNo1"></td>					
				</tr>
</c:if>
<c:if test="${!empty invForm.itemCode2}"> 			
				<tr id="r2">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode2" value="${invForm.itemCode2 }" size="12"  id="itemCode2"
				  				onchange="getItem(document.getElementById('itemCode2').value,2)"  >			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName2" value="${invForm.itemName2 }" maxlength="200" size="40" id="itemName2">					
					</td><td></td>
										
					<td align="center"><input	type="text"	name="unitName2" value="${invForm.unitName2 }" size="5" id="unitName2" >					
						<input	type="hidden" name="unitCode2" value="${invForm.unitCode2 }" id="unitCode2">
					</td><td></td>
					<td><input	type="text"	name="qty2" value="${invForm.qty2 }"  size="5" id="qty2" onchange="calLineItem(2);" ></td>
					<td></td>
					<td><input	type="text"	name="price2" value="${invForm.price2 }" size="5" id="price2" onchange="calLineItem(2);" ></td>
					<td></td>
					<td><input	type="text"	name="discountAmount2" value="${invForm.discountAmount2 }" size="5" id="discountAmount2" onchange="calLineItem(2);" ></td>
					<td></td>					
					<td><input	type="text"	name="amount2" value="${invForm.amount2 }" size="5" id="amount2" onchange="calUnitPrice(2)"></td>
					<td></td>
					<td><input	type="text"	name="poRefNo2" value="${invForm.poRefNo2 }" size="5" id="poRefNo2" >
						<input	type="hidden" name="stkReqNo2" value="" id="stkReqNo2"></td>
					<td><input	type="hidden" name="confirmNo2" value="" id="confirmNo2"></td>					
				</tr>
</c:if>
<c:if test="${!empty invForm.itemCode3}"> 			
				<tr id="r3">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode3" value="${invForm.itemCode3 }" size="12"  id="itemCode3"
				  				onchange="getItem(document.getElementById('itemCode3').value,3)"  >			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName3" value="${invForm.itemName3 }" maxlength="200" size="40" id="itemName3">					
					</td><td></td>
										
					<td align="center"><input	type="text"	name="unitName3" value="${invForm.unitName3 }" size="5" id="unitName3" >					
						<input	type="hidden" name="unitCode3" value="${invForm.unitCode3 }" id="unitCode3">
					</td><td></td>
					<td><input	type="text"	name="qty3" value="${invForm.qty3 }"  size="5" id="qty3" onchange="calLineItem(3);" ></td>
					<td></td>
					<td><input	type="text"	name="price3" value="${invForm.price3 }" size="5" id="price3" onchange="calLineItem(3);" ></td>
					<td></td>
					<td><input	type="text"	name="discountAmount3" value="${invForm.discountAmount3 }" size="5" id="discountAmount3" onchange="calLineItem(3);" ></td>
					<td></td>					
					<td><input	type="text"	name="amount3" value="${invForm.amount3 }" size="5" id="amount3" onchange="calUnitPrice(3)"></td>
					<td></td>
					<td><input	type="text"	name="poRefNo3" value="${invForm.poRefNo3 }" size="5" id="poRefNo3" >
						<input	type="hidden" name="stkReqNo3" value="" id="stkReqNo3"></td>
					<td><input	type="hidden" name="confirmNo3" value="" id="confirmNo3"></td>					
				</tr>
</c:if>
<c:if test="${!empty invForm.itemCode4}"> 			
				<tr id="r4">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode4" value="${invForm.itemCode4 }" size="12"  id="itemCode4"
				  				onchange="getItem(document.getElementById('itemCode4').value,4)"  >			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName4" value="${invForm.itemName4 }" maxlength="200" size="40" id="itemName4">					
					</td><td></td>
										
					<td align="center"><input	type="text"	name="unitName4" value="${invForm.unitName4 }" size="5" id="unitName4" >					
						<input	type="hidden" name="unitCode4" value="${invForm.unitCode4 }" id="unitCode4">
					</td><td></td>
					<td><input	type="text"	name="qty4" value="${invForm.qty4 }"  size="5" id="qty4" onchange="calLineItem(4);" ></td>
					<td></td>
					<td><input	type="text"	name="price4" value="${invForm.price4 }" size="5" id="price4" onchange="calLineItem(4);" ></td>
					<td></td>
					<td><input	type="text"	name="discountAmount4" value="${invForm.discountAmount4 }" size="5" id="discountAmount4" onchange="calLineItem(4);" ></td>
					<td></td>					
					<td><input	type="text"	name="amount4" value="${invForm.amount4 }" size="5" id="amount4" onchange="calUnitPrice(4)"></td>
					<td></td>
					<td><input	type="text"	name="poRefNo4" value="${invForm.poRefNo4 }" size="5" id="poRefNo4" >
						<input	type="hidden" name="stkReqNo4" value="" id="stkReqNo4"></td>
					<td><input	type="hidden" name="confirmNo4" value="" id="confirmNo4"></td>					
				</tr>
</c:if>
<c:if test="${!empty invForm.itemCode5}"> 			
				<tr id="r5">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode5" value="${invForm.itemCode5 }" size="12"  id="itemCode5"
				  				onchange="getItem(document.getElementById('itemCode5').value,5)"  >			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName5" value="${invForm.itemName5 }" maxlength="200" size="40" id="itemName5">					
					</td><td></td>
										
					<td align="center"><input	type="text"	name="unitName5" value="${invForm.unitName5 }" size="5" id="unitName5" >					
						<input	type="hidden" name="unitCode5" value="${invForm.unitCode5 }" id="unitCode5">
					</td><td></td>
					<td><input	type="text"	name="qty5" value="${invForm.qty5 }"  size="5" id="qty5" onchange="calLineItem(5);" ></td>
					<td></td>
					<td><input	type="text"	name="price5" value="${invForm.price5 }" size="5" id="price5" onchange="calLineItem(5);" ></td>
					<td></td>
					<td><input	type="text"	name="discountAmount5" value="${invForm.discountAmount5 }" size="5" id="discountAmount5" onchange="calLineItem(5);" ></td>
					<td></td>					
					<td><input	type="text"	name="amount5" value="${invForm.amount5 }" size="5" id="amount5" onchange="calUnitPrice(5)"></td>
					<td></td>
					<td><input	type="text"	name="poRefNo5" value="${invForm.poRefNo5 }" size="5" id="poRefNo5" >
						<input	type="hidden" name="stkReqNo5" value="" id="stkReqNo5"></td>
					<td><input	type="hidden" name="confirmNo5" value="" id="confirmNo5"></td>					
				</tr>
</c:if>
<c:if test="${!empty invForm.itemCode6}"> 			
				<tr id="r6">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode6" value="${invForm.itemCode6 }" size="12"  id="itemCode6"
				  				onchange="getItem(document.getElementById('itemCode6').value,6)"  >			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName6" value="${invForm.itemName6 }" maxlength="200" size="40" id="itemName6">					
					</td><td></td>
										
					<td align="center"><input	type="text"	name="unitName6" value="${invForm.unitName6 }" size="5" id="unitName6" >					
						<input	type="hidden" name="unitCode6" value="${invForm.unitCode6 }" id="unitCode6">
					</td><td></td>
					<td><input	type="text"	name="qty6" value="${invForm.qty6 }"  size="5" id="qty6" onchange="calLineItem(6);" ></td>
					<td></td>
					<td><input	type="text"	name="price6" value="${invForm.price6 }" size="5" id="price6" onchange="calLineItem(6);" ></td>
					<td></td>
					<td><input	type="text"	name="discountAmount6" value="${invForm.discountAmount6 }" size="5" id="discountAmount6" onchange="calLineItem(6);" ></td>
					<td></td>					
					<td><input	type="text"	name="amount6" value="${invForm.amount6 }" size="5" id="amount6" onchange="calUnitPrice(6)"></td>
					<td></td>
					<td><input	type="text"	name="poRefNo6" value="${invForm.poRefNo6 }" size="5" id="poRefNo6" >
						<input	type="hidden" name="stkReqNo6" value="" id="stkReqNo6"></td>
					<td><input	type="hidden" name="confirmNo6" value="" id="confirmNo6"></td>					
				</tr>
</c:if>
<c:if test="${!empty invForm.itemCode7}"> 			
				<tr id="r7">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode7" value="${invForm.itemCode7 }" size="12"  id="itemCode7"
				  				onchange="getItem(document.getElementById('itemCode7').value,7)"  >			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName7" value="${invForm.itemName7 }" maxlength="200" size="40" id="itemName7">					
					</td><td></td>
										
					<td align="center"><input	type="text"	name="unitName7" value="${invForm.unitName7 }" size="5" id="unitName7" >					
						<input	type="hidden" name="unitCode7" value="${invForm.unitCode7 }" id="unitCode7">
					</td><td></td>
					<td><input	type="text"	name="qty7" value="${invForm.qty7 }"  size="5" id="qty7" onchange="calLineItem(7);" ></td>
					<td></td>
					<td><input	type="text"	name="price7" value="${invForm.price7 }" size="5" id="price7" onchange="calLineItem(7);" ></td>
					<td></td>
					<td><input	type="text"	name="discountAmount7" value="${invForm.discountAmount7 }" size="5" id="discountAmount7" onchange="calLineItem(7);" ></td>
					<td></td>					
					<td><input	type="text"	name="amount7" value="${invForm.amount7 }" size="5" id="amount7" onchange="calUnitPrice(7)"></td>
					<td></td>
					<td><input	type="text"	name="poRefNo7" value="${invForm.poRefNo7 }" size="5" id="poRefNo7" >
						<input	type="hidden" name="stkReqNo7" value="" id="stkReqNo7"></td>
					<td><input	type="hidden" name="confirmNo7" value="" id="confirmNo7"></td>					
				</tr>
</c:if>
<c:if test="${!empty invForm.itemCode8}"> 			
				<tr id="r8">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode8" value="${invForm.itemCode8 }" size="12"  id="itemCode8"
				  				onchange="getItem(document.getElementById('itemCode8').value,8)"  >			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName8" value="${invForm.itemName8 }" maxlength="200" size="40" id="itemName8">					
					</td><td></td>
										
					<td align="center"><input	type="text"	name="unitName8" value="${invForm.unitName8 }" size="5" id="unitName8" >					
						<input	type="hidden" name="unitCode8" value="${invForm.unitCode8 }" id="unitCode8">
					</td><td></td>
					<td><input	type="text"	name="qty8" value="${invForm.qty8 }"  size="5" id="qty8" onchange="calLineItem(8);" ></td>
					<td></td>
					<td><input	type="text"	name="price8" value="${invForm.price8 }" size="5" id="price8" onchange="calLineItem(8);" ></td>
					<td></td>
					<td><input	type="text"	name="discountAmount8" value="${invForm.discountAmount8 }" size="5" id="discountAmount8" onchange="calLineItem(8);" ></td>
					<td></td>					
					<td><input	type="text"	name="amount8" value="${invForm.amount8 }" size="5" id="amount8" onchange="calUnitPrice(8)"></td>
					<td></td>
					<td><input	type="text"	name="poRefNo8" value="${invForm.poRefNo8 }" size="5" id="poRefNo8" >
						<input	type="hidden" name="stkReqNo8" value="" id="stkReqNo8"></td>
					<td><input	type="hidden" name="confirmNo8" value="" id="confirmNo8"></td>					
				</tr>
</c:if>
<c:if test="${!empty invForm.itemCode9}"> 			
				<tr id="r9">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode9" value="${invForm.itemCode9 }" size="12"  id="itemCode9"
				  				onchange="getItem(document.getElementById('itemCode9').value,9)"  >			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName9" value="${invForm.itemName9 }" maxlength="200" size="40" id="itemName9">					
					</td><td></td>
										
					<td align="center"><input	type="text"	name="unitName9" value="${invForm.unitName9 }" size="5" id="unitName9" >					
						<input	type="hidden" name="unitCode9" value="${invForm.unitCode9 }" id="unitCode9">
					</td><td></td>
					<td><input	type="text"	name="qty9" value="${invForm.qty9 }"  size="5" id="qty9" onchange="calLineItem(9);" ></td>
					<td></td>
					<td><input	type="text"	name="price9" value="${invForm.price9 }" size="5" id="price9" onchange="calLineItem(9);" ></td>
					<td></td>
					<td><input	type="text"	name="discountAmount9" value="${invForm.discountAmount9 }" size="5" id="discountAmount9" onchange="calLineItem(9);" ></td>
					<td></td>					
					<td><input	type="text"	name="amount9" value="${invForm.amount9 }" size="5" id="amount9" onchange="calUnitPrice(9)"></td>
					<td></td>
					<td><input	type="text"	name="poRefNo9" value="${invForm.poRefNo9 }" size="5" id="poRefNo9" >
						<input	type="hidden" name="stkReqNo9" value="" id="stkReqNo9"></td>
					<td><input	type="hidden" name="confirmNo9" value="" id="confirmNo9"></td>					
				</tr>
</c:if>
<c:if test="${!empty invForm.itemCode10}"> 			
				<tr id="r10">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode10" value="${invForm.itemCode10 }" size="12"  id="itemCode10"
				  				onchange="getItem(document.getElementById('itemCode10').value,10)"  >			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName10" value="${invForm.itemName10 }" maxlength="200" size="40" id="itemName10">					
					</td><td></td>
										
					<td align="center"><input	type="text"	name="unitName10" value="${invForm.unitName10 }" size="5" id="unitName10" >					
						<input	type="hidden" name="unitCode10" value="${invForm.unitCode10 }" id="unitCode10">
					</td><td></td>
					<td><input	type="text"	name="qty10" value="${invForm.qty10 }"  size="5" id="qty10" onchange="calLineItem(10);" ></td>
					<td></td>
					<td><input	type="text"	name="price10" value="${invForm.price10 }" size="5" id="price10" onchange="calLineItem(10);" ></td>
					<td></td>
					<td><input	type="text"	name="discountAmount10" value="${invForm.discountAmount10 }" size="5" id="discountAmount10" onchange="calLineItem(10);" ></td>
					<td></td>					
					<td><input	type="text"	name="amount10" value="${invForm.amount10 }" size="5" id="amount10" onchange="calUnitPrice(10)"></td>
					<td></td>
					<td><input	type="text"	name="poRefNo10" value="${invForm.poRefNo10 }" size="5" id="poRefNo10" >
						<input	type="hidden" name="stkReqNo10" value="" id="stkReqNo10"></td>
					<td><input	type="hidden" name="confirmNo10" value="" id="confirmNo10"></td>					
				</tr>
</c:if>
<c:if test="${!empty invForm.itemCode11}"> 			
				<tr id="r11">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode11" value="${invForm.itemCode11 }" size="12"  id="itemCode11"
				  				onchange="getItem(document.getElementById('itemCode11').value,11)"  >			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName11" value="${invForm.itemName11 }" maxlength="200" size="40" id="itemName11">					
					</td><td></td>
										
					<td align="center"><input	type="text"	name="unitName11" value="${invForm.unitName11 }" size="5" id="unitName11" >					
						<input	type="hidden" name="unitCode11" value="${invForm.unitCode11 }" id="unitCode11">
					</td><td></td>
					<td><input	type="text"	name="qty11" value="${invForm.qty11 }"  size="5" id="qty11" onchange="calLineItem(11);" ></td>
					<td></td>
					<td><input	type="text"	name="price11" value="${invForm.price11 }" size="5" id="price11" onchange="calLineItem(11);" ></td>
					<td></td>
					<td><input	type="text"	name="discountAmount11" value="${invForm.discountAmount11 }" size="5" id="discountAmount11" onchange="calLineItem(11);" ></td>
					<td></td>					
					<td><input	type="text"	name="amount11" value="${invForm.amount11 }" size="5" id="amount11" onchange="calUnitPrice(11)"></td>
					<td></td>
					<td><input	type="text"	name="poRefNo11" value="${invForm.poRefNo11 }" size="5" id="poRefNo11" >
						<input	type="hidden" name="stkReqNo11" value="" id="stkReqNo11"></td>
					<td><input	type="hidden" name="confirmNo11" value="" id="confirmNo11"></td>					
				</tr>
</c:if>
<c:if test="${!empty invForm.itemCode12}"> 			
				<tr id="r12">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode12" value="${invForm.itemCode12 }" size="12"  id="itemCode12"
				  				onchange="getItem(document.getElementById('itemCode12').value,12)"  >			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName12" value="${invForm.itemName12 }" maxlength="200" size="40" id="itemName12">					
					</td><td></td>
										
					<td align="center"><input	type="text"	name="unitName12" value="${invForm.unitName12 }" size="5" id="unitName12" >					
						<input	type="hidden" name="unitCode12" value="${invForm.unitCode12 }" id="unitCode12">
					</td><td></td>
					<td><input	type="text"	name="qty12" value="${invForm.qty12 }"  size="5" id="qty12" onchange="calLineItem(12);" ></td>
					<td></td>
					<td><input	type="text"	name="price12" value="${invForm.price12 }" size="5" id="price12" onchange="calLineItem(12);" ></td>
					<td></td>
					<td><input	type="text"	name="discountAmount12" value="${invForm.discountAmount12 }" size="5" id="discountAmount12" onchange="calLineItem(12);" ></td>
					<td></td>					
					<td><input	type="text"	name="amount12" value="${invForm.amount12 }" size="5" id="amount12" onchange="calUnitPrice(12)"></td>
					<td></td>
					<td><input	type="text"	name="poRefNo12" value="${invForm.poRefNo12 }" size="5" id="poRefNo12" >
						<input	type="hidden" name="stkReqNo12" value="" id="stkReqNo12"></td>
					<td><input	type="hidden" name="confirmNo12" value="" id="confirmNo12"></td>					
				</tr>
</c:if>
<c:if test="${!empty invForm.itemCode13}"> 			
				<tr id="r13">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode13" value="${invForm.itemCode13 }" size="12"  id="itemCode13"
				  				onchange="getItem(document.getElementById('itemCode13').value,13)"  >			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName13" value="${invForm.itemName13 }" maxlength="200" size="40" id="itemName13">					
					</td><td></td>
										
					<td align="center"><input	type="text"	name="unitName13" value="${invForm.unitName13 }" size="5" id="unitName13" >					
						<input	type="hidden" name="unitCode13" value="${invForm.unitCode13 }" id="unitCode13">
					</td><td></td>
					<td><input	type="text"	name="qty13" value="${invForm.qty13 }"  size="5" id="qty13" onchange="calLineItem(13);" ></td>
					<td></td>
					<td><input	type="text"	name="price13" value="${invForm.price13 }" size="5" id="price13" onchange="calLineItem(13);" ></td>
					<td></td>
					<td><input	type="text"	name="discountAmount13" value="${invForm.discountAmount13 }" size="5" id="discountAmount13" onchange="calLineItem(13);" ></td>
					<td></td>					
					<td><input	type="text"	name="amount13" value="${invForm.amount13 }" size="5" id="amount13" onchange="calUnitPrice(13)"></td>
					<td></td>
					<td><input	type="text"	name="poRefNo13" value="${invForm.poRefNo13 }" size="5" id="poRefNo13" >
						<input	type="hidden" name="stkReqNo13" value="" id="stkReqNo13"></td>
					<td><input	type="hidden" name="confirmNo13" value="" id="confirmNo13"></td>					
				</tr>
</c:if>
<c:if test="${!empty invForm.itemCode14}"> 			
				<tr id="r14">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode14" value="${invForm.itemCode14 }" size="12"  id="itemCode14"
				  				onchange="getItem(document.getElementById('itemCode14').value,14)"  >			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName14" value="${invForm.itemName14 }" maxlength="200" size="40" id="itemName14">					
					</td><td></td>
										
					<td align="center"><input	type="text"	name="unitName14" value="${invForm.unitName14 }" size="5" id="unitName14" >					
						<input	type="hidden" name="unitCode14" value="${invForm.unitCode14 }" id="unitCode14">
					</td><td></td>
					<td><input	type="text"	name="qty14" value="${invForm.qty14 }"  size="5" id="qty14" onchange="calLineItem(14);" ></td>
					<td></td>
					<td><input	type="text"	name="price14" value="${invForm.price14 }" size="5" id="price14" onchange="calLineItem(14);" ></td>
					<td></td>
					<td><input	type="text"	name="discountAmount14" value="${invForm.discountAmount14 }" size="5" id="discountAmount14" onchange="calLineItem(14);" ></td>
					<td></td>					
					<td><input	type="text"	name="amount14" value="${invForm.amount14 }" size="5" id="amount14" onchange="calUnitPrice(14)"></td>
					<td></td>
					<td><input	type="text"	name="poRefNo14" value="${invForm.poRefNo14 }" size="5" id="poRefNo14" >
						<input	type="hidden" name="stkReqNo14" value="" id="stkReqNo14"></td>
					<td><input	type="hidden" name="confirmNo14" value="" id="confirmNo14"></td>					
				</tr>
</c:if>
<c:if test="${!empty invForm.itemCode15}"> 			
				<tr id="r15">
					<td>&nbsp;
					</td>								
				  	<td><input 	type="text" name="itemCode15" value="${invForm.itemCode15 }" size="12"  id="itemCode15"
				  				onchange="getItem(document.getElementById('itemCode15').value,15)"  >			  		
				  	</td><td></td>
					<td><input 	type="text" name="itemName15" value="${invForm.itemName15 }" maxlength="200" size="40" id="itemName15">					
					</td><td></td>
										
					<td align="center"><input	type="text"	name="unitName15" value="${invForm.unitName15 }" size="5" id="unitName15" >					
						<input	type="hidden" name="unitCode15" value="${invForm.unitCode15 }" id="unitCode15">
					</td><td></td>
					<td><input	type="text"	name="qty15" value="${invForm.qty15 }"  size="5" id="qty15" onchange="calLineItem(15);" ></td>
					<td></td>
					<td><input	type="text"	name="price15" value="${invForm.price15 }" size="5" id="price15" onchange="calLineItem(15);" ></td>
					<td></td>
					<td><input	type="text"	name="discountAmount15" value="${invForm.discountAmount15 }" size="5" id="discountAmount15" onchange="calLineItem(15);" ></td>
					<td></td>					
					<td><input	type="text"	name="amount15" value="${invForm.amount15 }" size="5" id="amount15" onchange="calUnitPrice(15)"></td>
					<td></td>
					<td><input	type="text"	name="poRefNo15" value="${invForm.poRefNo15 }" size="5" id="poRefNo15" >
						<input	type="hidden" name="stkReqNo15" value="" id="stkReqNo15"></td>
					<td><input	type="hidden" name="confirmNo15" value="" id="confirmNo15"></td>					
				</tr>
</c:if>

			</tbody>					
		</table>
		</center>
     </fieldset>
 	</div>
	<div id="userPw01">
	<fieldset>
		<legend><b>ข้อมูลใบซื้ออุปกรณ์, วัตถุดิบ</b></legend>
		   <center> 
		   <table border="0" >
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				<td>&nbsp;</td>			
 				<td align="right">รหัสผู้ติดต่อ:</td>
 				<td><input type="text" name="contactCode" value="${invForm.contactCode }" id='contactCode' readonly="readonly"></td>
 				<td ></td>				 				 				
 				<td align="right">ยอดรวมมูลค่าสินค้า:</td>
 				<td><input type="text" name="sumOfItemAmount" value="${invForm.sumOfItemAmount }" id="sumOfItemAmount" onchange="calTaxAmount();"></td>
 				<td ></td>	
 			</tr>		   													
			<tr>
				<td align="right">รหัสแผนก:</td>
				<td><input type="text" name="departCode" maxlength="3" value="${invForm.departCode }" id="departCode" ></td>
				<td ></td>			
 				<td align="right">โครงการ:</td>
 				<td><input type="text" name="projectCode" value="${invForm.projectCode }" ></td>
 				<td ></td>				 				 				
 				<td align="right">ส่วนลดบาท:</td>
 				<td><input type="text" name="discountAmount" value="${invForm.discountAmount }" id='discountAmount' onchange="calTaxAmount();"></td>
 				<td ></td>	
 			</tr>
 			<tr>
 				<td align="right">การจัดสรร:</td>
 				<td><input type="text" name="allocateCode" value="${invForm.allocateCode }" id='allocateCode' readonly="readonly"></td>
 				<td ></td>
 				<td align="right">วันที่วางบิล:</td>
 				<td><input type="text" name="statementDate" value="" id='statementDate' readonly="readonly"></td>
 				<td ></td>
 				<td align="right">ภาษีมูลค่าเพิ่ม:</td>
 				<td><input type="text" name="taxAmount" value="${invForm.taxAmount }" id="taxAmount" onchange="calTaxAmount();"></td>
 				<td ></td> 				 				 				
 			</tr>
 			<tr>
 				<td align="right">เครดิต(วัน):</td>
 				<td><input type="text" name="creditDay" value="" id='creditDay' readonly="readonly"></td>
 				<td ></td>
 				<td align="right">วันที่ครบกำหนด:</td>
 				<td><input type="text" name="dueDate" value="" id='dueDate' readonly="readonly"></td>
 				<td ></td> 				
 				<td align="right">มูลค่ารวมภาษี:</td>
 				<td><input type="text" name="totalAmount" value="${invForm.totalAmount }" id="totalAmount"></td>
 				<td ></td>	 				 			 				 			 				 				
 			</tr>
 			<tr>
 				<td align="right">กลุ่มเอกสาร:</td>
 				<td><input type="text" name="billGroup" value="${invForm.billGroup }" id='billGroup'></td>
 				<td ></td>
 				<td align="right">อัตราภาษีมูลค่าเพิ่ม:</td>
 				<td><input type="text" name="taxRate" value="7" id='taxRate'></td>
 				<td ></td> 				
 				<td align="right">มูลค่าสินค้ายกเว้นภาษี:</td>
 				<td><input type="text" name="exceptTaxAmount" value="" id="exceptTaxAmount"></td>
 				<td ></td>	 				 			 				 			 				 				
 			</tr> 			 				 	
 			<tr>
 				<td align="right">รหัสสกุลเงิน:</td>
 				<td><select name="currencyCode">
 						<option value="BAHT" selected="selected" >บาท 						 						
 					</select> </td>
 				<td ></td>	

 				<td align="right">อัตราแลกเปลี่ยน:</td>
 				<td><input type="text" name="exchangeRate" id="exchangeRate" value="1" readonly="readonly"> </td>
 				<td ></td>	

 				<td align="right">มูลค่าสุทธิ:</td>
 				<td><input type="text" name="netAmount" value="${invForm.netAmount }" id="netAmount" onchange="dataToPayAmount();"></td>
 				<td ></td>	
 			</tr> 			 				 							
		</table>
		</center>   <br/>  	
		<font size='2'>หมายเหตุ : <font color="red">*</font> คือข้อมูลที่ต้องใส่</font>
     </fieldset></div>
	<div id="userPw01">
	<fieldset>
		<legend><b>บันทึกจ่ายเงิน -วงเงินสดย่อย</b></legend>
		   <center> 
		   <table border="0" >
			<tr>
				<td width="160"align="right">ยอดเงินสดย่อย:</td>
				<td width="140"><input type="text" name="payAmount" value="${invForm.payAmount }" id="payAmount" size="9" ></td>
				<td width="20">&nbsp;</td>				
				<td width="160"align="right">รหัสวงเงินสดย่อย:</td>
				<td width="160"><select name="refNo" id="refNo" >
									<option value=""></option>
									<option value="ST">ST-Preecha</option>
								</select>
				</td>
				<td width="20">&nbsp;</td>					
			</tr>

		</table>
		</center>
     </fieldset></div>      	
 	<table border="0" align="center" width="100%">
 		<tr>
 			<td align="center" ><html:submit value="บันทึกการซื้อ " onclick="return confirm('ยืนยัน ?');" /></td>
 			<td align="center" ><html:reset value="เคลียร์หน้าบันทึก"/></td>
			<td align="center" ><html:button  value="กลับไปรายการเมนู" property="show1" 
 			onclick="gotoMenu()"  /></td> 			
 		</tr>
 	</table>    	    	    	
    </html:form><br>
    </div>

<script type="text/javascript">

	for(var i=1; i<=15; i++) {
		
		var item = document.getElementById("itemCode"+i).value;
		//alert(item+'=>'+i);
		if(item=="") {
			idArray[i] = 0;
		}else {
			idArray[i] = 1;
		}		
	}
	
function refreshForm() {
	var lAddr = document.getElementById("localAddr").value;
	var lPort = document.getElementById("localPort").value;
	var ctPath = document.getElementById("contextPath").value;
	var docNo = document.getElementById("docNo").value
	window.location = "http://"+lAddr+":"+lPort+ctPath+"/StkReq.do?mode=edit&docNo="+docNo;	
}
function gotoMenu() {
	var lAddr = document.getElementById("localAddr").value;
	var lPort = document.getElementById("localPort").value;
	var ctPath = document.getElementById("contextPath").value;
	window.location = "http://"+lAddr+":"+lPort+ctPath+"/Login.do?mode=check";
}
</script>
<input type="hidden" value="<%=request.getLocalAddr() %>" id="localAddr">
<input type="hidden" value="<%=request.getLocalPort() %>" id="localPort">
<input type="hidden" value="<%=request.getContextPath() %>" id="contextPath">

<!-- 
<a href="#" class="add"><img src="add.png" width="24" height="24" alt="add" title="add input" /></a> 
<a href="#" class="reset"><img src="reset.png" width="24" height="24" alt="reset" /></a>
 -->
 
 </div>
 </div>
 
</body>
</html:html>